package com.lanhai.longheng;

import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor; 


@Configuration  
public class ThreadConfig {
	 @Bean
     public Executor agvExecutor() {
          ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
          executor.setCorePoolSize(40); //核心线程池数
          executor.setMaxPoolSize(250); //最大线程池数
          executor.setQueueCapacity(1000); //任务队列的容量
          executor.setKeepAliveSeconds(2);  //非核心线程的存活时间
          
          /**
           * 拒绝处理策略
           * CallerRunsPolicy()：交由调用方线程运行，比如 main 线程。
           * AbortPolicy()：直接抛出异常。
           * DiscardPolicy()：直接丢弃。
           * DiscardOldestPolicy()：丢弃队列中最老的任务。
           */
          //executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardOldestPolicy());
          executor.initialize();
          return executor;
     } 
}
